package org.xyl.game.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.xyl.game.entity.Maproom;
import org.xyl.game.service.MaproomService;
import org.xyl.game.tool.GsonUtil;

@Controller
public class MaproomController {
    @Autowired
    private MaproomService maproomService;

    @PostMapping("/createroom")
    @ResponseBody
    public String createRoom(String username, double longitude, double latitude) {
        Maproom room = maproomService.createRoom(username, longitude, latitude);

        return GsonUtil.getGsonBuilder().create().toJson(room);


    }

    @PostMapping("/joinroom")
    @ResponseBody
    public String joinRoom(int id) {
        return GsonUtil.getGsonBuilder().create().toJson(maproomService.joinRoom(id));
    }

    @PostMapping("/queryroom")
    @ResponseBody
    public String queryRoom(int id) {
        return GsonUtil.getGsonBuilder().create().toJson(maproomService.joinRoom(id));
    }


}
